//
//  ZJTuiGuangShuoMingVC.m
//  英伦府邸
//
//  Created by IOS_DEVELOPER on 2017/8/11.
//  Copyright © 2017年 英伦府邸. All rights reserved.
//

#import "ZJTuiGuangShuoMingVC.h"
#import "ZJExtensionAgentController.h"
#import "ZJOnlinePayHouseController.h"
@interface ZJTuiGuangShuoMingVC (){
    NSArray *_titleArr;
    NSArray *_btTitleArr;
    NSArray *_imgArr;
}
@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;
@property (weak, nonatomic) IBOutlet UIButton *sureBtn;
@property (strong, nonatomic) UIPageControl * pageControl;
@end

@implementation ZJTuiGuangShuoMingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    if ([self.titleStr isEqualToString:@"开始购房"]) {
        
        _titleArr = @[@"不用到现场",@"将心仪的户型添加到预选区",@"当您抢到房后"];
        _btTitleArr = @[@"在家也能买到心仪的房子",@"开盘时直接就能抢",@"我们会立即与您联系,沟通余下事宜"];
        _imgArr = @[[Utils imgPath:@"zxgf_smta@3x.png"],[Utils imgPath:@"zxgf_smtb@3x.png"],[Utils imgPath:@"zxgf_smtc@3x.png"]];
        [self.sureBtn setTitle:@"开始购房" forState:0];
        
    }else{
        _titleArr = @[@"成为推广员",@"让朋友扫描二维码安装APP",@"我的客户完成三步操作"];
        _btTitleArr = @[@"将二维码分享出去",@"输入我的推广码成为我的客户",@"我就能获取佣金"];
        _imgArr = @[[Utils imgPath:@"tqbm_smta@3x.png"],[Utils imgPath:@"tqbm_smtb@3x.png"],[Utils imgPath:@"tqbm_smtc@3x.png"]];
    }
    _pageControl = [[UIPageControl alloc] init];
    _pageControl.numberOfPages = 3;//指定页面个数
    _pageControl.currentPage = 0;//指定pagecontroll的值，默认选中的小白点（第一个）
    //添加委托方法，当点击小白点就执行此方法
    
    _pageControl.pageIndicatorTintColor = RGB(219, 219, 219);// 设置非选中页的圆点颜色
    
    _pageControl.currentPageIndicatorTintColor = [Utils colorWithHexString:allConstHexColor]; // 设置选中页的圆点颜色
    
    
    self.scrollview.contentSize = CGSizeMake(SCREEN_WIDTH * 3, 0);
    
    for (int i=0; i < 3; i ++) {
        UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * i, 0, SCREEN_WIDTH, SCREEN_WIDTH)];
        imageView.image = [UIImage imageWithContentsOfFile:_imgArr[i]];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * i , imageView.height + 20 , SCREEN_WIDTH , 24)];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:[Utils iphone5AutoScaleW:23.0f]];
        label.textColor = RGB(51, 51, 51);
        label.text = _titleArr[i];
        
        UILabel * label2 = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * i , label.height + label.y + 10 , SCREEN_WIDTH , 21)];
        label2.textAlignment = NSTextAlignmentCenter;
        label2.font = [UIFont systemFontOfSize:[Utils iphone5AutoScaleW:13.0f]];
        label2.textColor = RGB(153, 153, 153);
        label2.text = _btTitleArr[i];
        
        [self.scrollview addSubview:imageView];
        [self.scrollview addSubview:label];
        [self.scrollview addSubview:label2];
        
        if (i == 2) {
            _pageControl.frame = CGRectMake((SCREEN_WIDTH - 60)/2, label2.y + label2.height + 14, 60, 20);//指定位置大小
            [self.view addSubview:_pageControl];
        }
    }

    [self.sureBtn setBackgroundColor:[Utils colorWithHexString:allConstHexColor]];
}
- (IBAction)sureBtn:(UIButton *)sender {
    
    if ([self.titleStr isEqualToString:@"开始购房"]) {
        
        ZJOnlinePayHouseController *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJOnlinePayHouseController"];
        vc.prModel = GET_PROJECTINFO;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else{
    
    NSDictionary *parameter = [LRNetwork requestParameter:@{}];
    NSString *url = [LRNetwork requestURL:@"cgi/promoter_apply.php"];
    
    [HUD showLoading:@"申请中..."];
    
    [LRNetwork netRequestPOSTWithRequestURL:url withParameter:parameter withReturnValeuBlock:^(id returnValue) {
        
        [HUD showSucceedMsg:@"申请成功!"];
        ZJUserModel * model = GET_USERINFO;
        model.money_mission = [NSString stringWithFormat:@"%@",@([model.money_mission floatValue] + [returnValue[@"money"] floatValue])];
        model.money_total = [NSString stringWithFormat:@"%@",@([model.money_total floatValue] + [returnValue[@"money"] floatValue])];
        model.is_promoter = @"1";
        SYN_USER(model);
        ZJExtensionAgentController *vc = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:@"ZJExtensionAgentController"];
        [self.navigationController pushViewController:vc animated:YES];
        
    } withErrorCodeBlock:^(NSInteger errorCode, NSString *errorMessage) {
        [HUD showErrorMsg:errorMessage];
    } withFailureBlock:^{
        
    }];
        
    }
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    int page = scrollView.contentOffset.x / scrollView.frame.size.width;
    //    NSLog(@"%d", page);
    
    // 设置页码
    _pageControl.currentPage = page;
}

@end
